[prism] Fix leading indentation calculation for squiggly heredocs #723
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #699
We unfortunately have to do all the indentation stripping for squiggly heredocs ourselves (see #640 for details), but the logic for this had some slight issues, which is that it was looking for the least leading whitespace of any
StringNodein a heredoc. This isn't quite correct, since not everyStringNodeis at the beginning of a line in source -- it could be following an interpolation or might not be the left-most string node in the heredoc.Prism does provide us with an
unescapedstring value, which for squiggly heredocs has the necessary leading whitespace stripped away, so we can find the indentation instead by looking at the difference between theunescapedand thecontent_locvalues. This PR updates the indentation calculation to do that -- it looks for anyStringNodewith different-lengthunescapedvscontent_locvalues and uses the difference in their lengths as the leading-indentation of the heredoc.